package io.bba.boot.app.controller;

import io.bba.boot.app.dto.BatchCrawlerDataDto;
import io.bba.boot.app.dto.CrawlerDataDto;
import io.bba.boot.auth.annotation.IgnoreLogin;
import io.bba.boot.framework.page.Paging;
import io.bba.boot.framework.response.ApiResult;
import io.bba.boot.app.query.AppCrawlerDataQuery;
import io.bba.boot.app.service.CrawlerDataService;
import io.bba.boot.app.vo.AppCrawlerDataVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * App采集数据 控制器
 *
 * @author zs
 * @since 2024-03-19
 */
@Slf4j
@RestController
@Tag(name = "App采集数据")
@RequestMapping("/app/crawlerData")
public class AppCrawlerDataController {

    @Autowired
    private CrawlerDataService crawlerDataService;

    /**
     * 获取App采集数据详情
     *
     * @param id
     * @return
     * @throws Exception
     */
    @Operation(summary = "获取App采集数据详情")
    @PostMapping("/getAppCrawlerData/{id}")
    public ApiResult<AppCrawlerDataVo> getAppCrawlerData(@PathVariable Long id) {
        log.info("获取App采集数据详情：{}", id);
        AppCrawlerDataVo appCrawlerDataVo = crawlerDataService.getAppCrawlerDataById(id);
        return ApiResult.success(appCrawlerDataVo);
    }

    /**
     * 获取App采集数据分页列表
     *
     * query
     * @return
     * @throws Exception
     */
    @Operation(summary = "获取App采集数据分页列表")
    @PostMapping("/getAppCrawlerDataPage")
    public ApiResult<AppCrawlerDataVo> getAppCrawlerDataPage(@Valid @RequestBody AppCrawlerDataQuery query) {
        log.info("获取App采集数据分页列表：{}", query);
        Paging<AppCrawlerDataVo> paging = crawlerDataService.getAppCrawlerDataPage(query);
        return ApiResult.success(paging);
    }

    /**
     * 批量新增采集数据
     *
     * query
     * @return
     * @throws Exception
     */
    @Operation(summary = "批量新增采集数据")
    @PostMapping("/batchAddCrawlerData")
    @IgnoreLogin
    public ApiResult<AppCrawlerDataVo> batchAddCrawlerData(@Valid @RequestBody BatchCrawlerDataDto dtos) {
        log.info("批量新增采集数据：{}", dtos);
        boolean flag = crawlerDataService.batchAddCrawlerData(dtos);
        return ApiResult.result(flag);
    }

}
